package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.UserDao;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author YDW
 * projectName:project2202_3
 * time:2022/5/13 17:18
 * description:
 */
@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;

    @Override
    public User findById(Integer id) {
        return userDao.findById(id);
    }

    @Override
    public PageInfo<User> findByPage(Integer pageNum, Integer pageSize) {
//        使用分页插件
        //开始分页
        PageHelper.startPage(pageNum,pageSize);
        //查询所有
        List<User> userList=userDao.findAll();
        //创建PageInfo对象
        PageInfo<User> pageInfo=new PageInfo<>(userList);


        return pageInfo;
    }


}
